package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.generator.dao.SpecDao;
import io.renren.modules.generator.entity.SpecEntity;
import io.renren.modules.generator.service.SpecService;
import io.renren.modules.generator.vo.SpecVo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service("specService")
public class SpecServiceImpl extends ServiceImpl<SpecDao, SpecEntity> implements SpecService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<SpecEntity> page = this.selectPage(
                new Query<SpecEntity>(params).getPage(),
                new EntityWrapper<SpecEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SpecVo> listForSelect() {
        List<SpecEntity> specs = this.selectList(Condition.empty());
        List<SpecVo> response = new ArrayList<>();
        specs.stream().forEach(x->{
            SpecVo s = new SpecVo();
            s.setLabel(x.getUnFirName());
            s.setValue(x.getId());
            response.add(s);
        });
        return response;
    }

}
